package com.ziven.learn.dispatch;

import androidx.annotation.NonNull;

import com.ziven.common.widget.setting.BasePreferenceItem;
import com.ziven.common.widget.setting.ClickPreferenceItem;
import com.ziven.common.widget.setting.PreferenceFragment;
import com.ziven.common.widget.setting.PreferenceItemsFactory;
import com.ziven.common.widget.setting.RedPointPreferenceItem;
import com.ziven.common.widget.value.Title;
import com.ziven.easygo.autowired.EasyGo;
import com.ziven.easygo.ui.AbstractBaseActivity;
import com.ziven.learn.LearnInterface;
import com.ziven.learn.R;
import com.ziven.processor.Learn;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Ziven
 */
@Learn(learn = "设置")
public class SettingLean implements LearnInterface {

    @Override
    public void learn() {
        EasyGo.easyGo(SettingActivity.class);
    }

    public static class SettingActivity extends AbstractBaseActivity implements PreferenceItemsFactory {

        @Override
        protected Object obtainLayout() {
            return R.layout.activity_container;
        }

        @Override
        protected void initLayout() {
            getSupportFragmentManager()
                    .beginTransaction()
                    .add(R.id.container, PreferenceFragment.newInstance(this))
                    .commitNow();
        }

        @Override
        protected void destroyLayout() {

        }

        @NonNull
        @Override
        public List<BasePreferenceItem> getPreferenceItems() {
            List<BasePreferenceItem> list = new ArrayList<>();

            RedPointPreferenceItem item =
                    new RedPointPreferenceItem()
                    .accept(my -> {
                        my.title = Title.title("测试");
                        my.subTitle2 = Title.title("测试副标题");
                        my.toast = "Test Toast";
                    });

            ClickPreferenceItem item1 =
                    new ClickPreferenceItem()
                    .accept(my -> {
                        my.title = Title.title("测试1");
                        my.subTitle1 = Title.title("测试副标题1");
                        my.toast = "Test Toast 1";
                    });

            list.add(item);
            list.add(item1);
            return list;
        }
    }
}
